package com.company.lanqiao;

import java.util.Scanner;

public class Distance {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt(),m = sc.nextInt(),n = sc.nextInt();

        int temp01 = 0;
        int i01 = 1;
        while (temp01 < m){
            temp01 = w * i01++;
        }
        i01--;

        int temp02 = 0;
        int i02 = 1;
        while (temp02 < n){
            temp02 = w * i02++;
        }
        i02--;

        int i = Math.max(i01,i02);


        int[][] map = new int[i][w];
        boolean flag = false;
        int k = 0;
        int indexX0 = 0,indexY0 = 0;
        int indexX1 = 0,indexY1 = 0;
        for (i = 0; i < map.length; i++) {
            for (int j = 0; j < map[i].length; j++) {
                // 反向
                if (flag) {
                    map[i][map[i].length - j - 1] = ++k;
                    if (k == m) {
                        indexX0 = i;
                        indexY0 = map[i].length - j - 1;
                    }
                    if (k == n) {
                        indexX1 = i;
                        indexY1 = map[i].length - j - 1;
                    }
                } else {
                    map[i][j] = ++k;
                    if (k == m) {
                        indexX0 = i;
                        indexY0 = j;
                    }
                    if (k == n) {
                        indexX1 = i;
                        indexY1 = j;
                    }
                }

            }
            flag = !flag;
        }

        System.out.println(Math.abs(indexX0 - indexX1) + Math.abs(indexY0 - indexY1));

    }
}
